home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / dev / lang / Python16_Src.lha / Python16_Source / Parser / intrcheck.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-10  |  3.5 KB  |  216 lines

  1. /* Check for interrupts */
  2.  
  3. #include "config.h"
  4.  
  5. /* config.h may or may not define DL_IMPORT */
  6. #ifndef DL_IMPORT    /* declarations for DLL import/export */
  7. #define DL_IMPORT(RTYPE) RTYPE
  8. #endif
  9.  
  10. #include "myproto.h"
  11. #include "mymalloc.h" /* For ANY */
  12. #include "intrcheck.h"
  13.  
  14. /* Copied here from ceval.h -- can't include that file. */
  15. int Py_AddPendingCall Py_PROTO((int (*func) Py_PROTO((ANY *)), ANY *arg));
  16.  
  17.  
  18. #ifdef QUICKWIN
  19.  
  20. #include <io.h>
  21.  
  22. void
  23. PyOS_InitInterrupts()
  24. {
  25. }
  26.  
  27. void
  28. PyOS_FiniInterrupts()
  29. {
  30. }
  31.  
  32. int
  33. PyOS_InterruptOccurred()
  34. {
  35.     _wyield();
  36. }
  37.  
  38. #define OK
  39.  
  40. #endif /* QUICKWIN */
  41.  
  42. #if defined(_M_IX86) && !defined(__QNX__)
  43. #include <io.h>
  44. #endif
  45.  
  46. #if defined(MSDOS) && !defined(QUICKWIN)
  47.  
  48. #ifdef __GNUC__
  49.  
  50. /* This is for DJGPP's GO32 extender.  I don't know how to trap
  51.  * control-C  (There's no API for ctrl-C, and I don't want to mess with
  52.  * the interrupt vectors.)  However, this DOES catch control-break.
  53.  * --Amrit
  54.  */
  55.  
  56. #include <go32.h>
  57.  
  58. void
  59. PyOS_InitInterrupts()
  60. {
  61.     _go32_want_ctrl_break(1 /* TRUE */);
  62. }
  63.  
  64. void
  65. PyOS_FiniInterrupts()
  66. {
  67. }
  68.  
  69. int
  70. PyOS_InterruptOccurred()
  71. {
  72.     return _go32_was_ctrl_break_hit();
  73. }
  74.  
  75. #else /* !__GNUC__ */
  76.  
  77. /* This might work for MS-DOS (untested though): */
  78.  
  79. void
  80. PyOS_InitInterrupts()
  81. {
  82. }
  83.  
  84. void
  85. PyOS_FiniInterrupts()
  86. {
  87. }
  88.  
  89. int
  90. PyOS_InterruptOccurred()
  91. {
  92.     int interrupted = 0;
  93.     while (kbhit()) {
  94.         if (getch() == '\003')
  95.             interrupted = 1;
  96.     }
  97.     return interrupted;
  98. }
  99.  
  100. #endif /* __GNUC__ */
  101.  
  102. #define OK
  103.  
  104. #endif /* MSDOS && !QUICKWIN */
  105.  
  106.  
  107. #ifdef macintosh
  108.  
  109. /* The Mac interrupt code has moved to macglue.c */
  110. #define OK
  111.  
  112. #endif /* macintosh */
  113.  
  114.  
  115. #ifndef OK
  116.  
  117. /* Default version -- for real operating systems and for Standard C */
  118.  
  119. #include <stdio.h>
  120. #include <string.h>
  121. #include <signal.h>
  122. #ifdef HAVE_UNISTD_H
  123. #include <unistd.h>
  124. #endif
  125.  
  126. static int interrupted;
  127.  
  128. void
  129. PyErr_SetInterrupt()
  130. {
  131.     interrupted = 1;
  132. }
  133.  
  134. extern int PyErr_CheckSignals();
  135.  
  136. /* ARGSUSED */
  137. static RETSIGTYPE
  138. #if defined(_AMIGA) || defined(_M_IX86) && !defined(__QNX__)
  139. intcatcher(int sig)    /* So the C compiler shuts up */
  140. #else /* _M_IX86 */
  141. intcatcher(sig)
  142.     int sig; /* Not used by required by interface */
  143. #endif /* _M_IX86 */
  144. {
  145.     extern void Py_Exit Py_PROTO((int));
  146.     static char message[] =
  147. "python: to interrupt a truly hanging Python program, interrupt once more.\n";
  148.     switch (interrupted++) {
  149.     case 0:
  150.         break;
  151.     case 1:
  152.         write(2, message, strlen(message));
  153.         break;
  154.     case 2:
  155.         interrupted = 0;
  156.         Py_Exit(1);
  157.         break;
  158.     }
  159.     signal(SIGINT, intcatcher);
  160.     Py_AddPendingCall(PyErr_CheckSignals, NULL);
  161. }
  162.  
  163. static RETSIGTYPE (*old_siginthandler)() = SIG_DFL;
  164.  
  165. void
  166. PyOS_InitInterrupts()
  167. {
  168.     if ((old_siginthandler = signal(SIGINT, SIG_IGN)) != SIG_IGN)
  169.         signal(SIGINT, intcatcher);
  170. #ifdef HAVE_SIGINTERRUPT
  171.     /* This is for SunOS and other modern BSD derivatives.
  172.        It means that system calls (like read()) are not restarted
  173.        after an interrupt.  This is necessary so interrupting a
  174.        read() or readline() call works as expected.
  175.        XXX On old BSD (pure 4.2 or older) you may have to do this
  176.        differently! */
  177.     siginterrupt(SIGINT, 1);
  178. #endif /* HAVE_SIGINTERRUPT */
  179. }
  180.  
  181. void
  182. PyOS_FiniInterrupts()
  183. {
  184.     signal(SIGINT, old_siginthandler);
  185. }
  186.  
  187. int
  188. PyOS_InterruptOccurred()
  189. {
  190. #ifdef __SASC
  191.     extern void __regargs __chkabort(void);
  192.     extern void chkabort(void);
  193.  
  194.     chkabort();        /* explicit Amiga SAS/C ^C check */
  195. #endif
  196.     if (!interrupted)
  197.         return 0;
  198.     interrupted = 0;
  199.     return 1;
  200. }
  201.  
  202. #ifdef __SASC
  203. /* Amiga SAS/C replacement ^C handler */
  204. void __regargs _CXBRK(void)
  205. {
  206.     interrupted=1;
  207. }
  208. #endif
  209.  
  210. #endif /* !OK */
  211.  
  212. void
  213. PyOS_AfterFork()
  214. {
  215. }
  216.